package guitforl.parsers.xml

import scala.xml.{NodeSeq}
import scala.collection.mutable.{HashMap}
import guitforl.wrappers.{LabelWrapper, TabWrapper, EditWrapper, ChartWrapper}

/**
 * Created by IntelliJ IDEA.
 * User: artem
 * Date: Jun 25, 2010
 * Time: 9:46:27 PM
 * To change this template use File | Settings | File Templates.
 */
object implementationReader {
  def read(tabXMLBlock: NodeSeq, tab: TabWrapper) = {
    (tabXMLBlock \ "composite").foreach {
      compositeNode => (compositeNode \ "_").foreach { node =>
        val areaComposite = tab.getComposite((compositeNode \ "@name").text);
        node match
        {
          case <edit>{_*}</edit> => {
              tab.addEdit((node \ "@paramName").text, new EditWrapper(areaComposite, (node \ "defaultValue").text))
            }
          case <label>{_*}</label> => {
	          val dataFileName = (node \ "dataFileName")
	          if(dataFileName.nonEmpty){
		          tab.addUpdatebleWidget(new LabelWrapper(areaComposite, Some(dataFileName.text), (node \ "defaultValue").text))
	          }
	          else{
		          tab.addLabel(new LabelWrapper(areaComposite, None, (node \ "defaultValue").text))
	          }
	        }
          case <chart>{_*}</chart> => {
              // TODO : How to be with params by defaulth ???
              tab.addUpdatebleWidget(new ChartWrapper(areaComposite, (node \ "@name").text))
          }
          case <table>{_*}</table> => {
          }
          case <button>{_*}</button> => {
          }
        }
      }
    }
  }
}